package ui.panels.messageBox;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle;

import ui.panels.commands.SetEnablecommand;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 * @author vladimir && alon
 *
 */
public class MessageBoxPanel extends JPanel{

	private String 			message = null;
	private JLabel 			messageLabel;
	private JButton			button;
	private MessageBoxFrame	myFrame;
	
	public MessageBoxPanel(MessageBoxFrame myFrame ,String message)
	{
		this.myFrame = myFrame;
		this.message = message;
		
		initialize();
	}
	
	
	/**
	 * Initialize the panel
	 */
	private void initialize()
	{
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(300, 250));
	
			messageLabel = new JLabel(message , JLabel.CENTER);
			messageLabel.setFont(new Font(Font.SANS_SERIF, Font.LAYOUT_NO_LIMIT_CONTEXT , 18));
		
			button = new JButton("OK");
			button.setFont(new Font(Font.SERIF, Font.TYPE1_FONT, 14));
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(52, 52)
				.addComponent(messageLabel, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
				.addGap(40)
				.addComponent(button, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(65, Short.MAX_VALUE));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(54, 54)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(messageLabel, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addGap(64)
				        .addComponent(button, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 62, Short.MAX_VALUE)))
				.addContainerGap(45, 45));

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		//set the OK Button
		setListeners();
	}
	
	
	/**
	 * Set the components listeners
	 */
	private void setListeners()
	{
		button.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				//set enable the prime GUI , use via command pattern
				SetEnablecommand enableCommand = new SetEnablecommand();
				enableCommand.setArg(true);
				enableCommand.execute();	
				
				//close this error frame
				myFrame.dispose();
			}
		});
	}
	
	
}
